package com.hisan.freeride.home.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;


import com.hisan.freeride.R;
import com.hisan.freeride.common.view.ColorTextView;
import com.hisan.freeride.home.model.ItemContacts;


import java.util.ArrayList;


/**
 * 搜索的条目
 * Created by Han on 2017/4/25.
 */

public class AddressAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    private ArrayList<ItemContacts> list;

    public AddressAdapter(Context context, ArrayList<ItemContacts> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.activity_address_search_item, parent, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder holde = (ViewHolder) holder;
        final ItemContacts item = list.get(position);
        //设置字体颜色
        holde.searchNameTv.showTextHighlight(item.name, item.getColorName());
        holde.searchPhoneTv.showTextHighlight(item.number, item.getColorNumberName());
    }


    @Override
    public int getItemCount() {
        return list.size();
    }


    class ViewHolder extends RecyclerView.ViewHolder {
//        @Bind(R.id.search_icon_iv)
        ImageView searchIconIv;

        ColorTextView searchNameTv;

        ColorTextView searchPhoneTv;

        ViewHolder(View view) {
            super(view);
            searchIconIv=view.findViewById(R.id.search_icon_iv);
            searchNameTv=view.findViewById(R.id.search_name_tv);
            searchPhoneTv=view.findViewById(R.id.search_phone_tv);
//            ButterKnife.bind(this, view);
        }
    }
}
